<template>
  <page-layout :noToolbar="true">

    <el-card class="box-card">
      <div class="card-header">区域完成率统计</div>
      <el-card class="box-card">
        <el-form ref="searchCondition" :model="searchCondition" label-width="80px" inline>

          <el-form-item label="查询时间">
            <el-date-picker
              v-model="value4"
              type="daterange"
              range-separator="至"
              start-placeholder="查询开始日期"
              end-placeholder="查询截至日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="排序">
            <el-select v-model="searchCondition.by" placeholder="请选择" >
              <el-option
                v-for="item in SortCategory"
                :key="item.value"
                :label="item.text"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="排序方式">
            <el-select v-model="searchCondition.order" placeholder="请选择" >
              <el-option
                v-for="item in SortType"
                :key="item.value"
                :label="item.text"
                :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="refresh(1)">查询</el-button>
          </el-form-item>
        </el-form>
      </el-card>
          <el-card class="box-card">
            <el-table
              :data="areaStatisList" border stripe
              v-loading="loading"
              element-loading-text="拼命统计中"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(0, 0, 0, 0.8)">
              <el-table-column
                prop="areaCode"
                label="区域代码"
                width="100">
              </el-table-column>
              <el-table-column prop="areaName" label="区域名称">
              </el-table-column>
              <el-table-column prop="trainDoneRate" label="每日练习完成率" >
                <template slot-scope="scope">
                  {{scope.row.trainDoneRate}}
                </template>
              </el-table-column>
              <el-table-column
                prop="taskDoneRate"
                label="下发任务完成率">
                <template slot-scope="scope">
                  {{scope.row.taskDoneRate}}
                </template>
              </el-table-column>
              <el-table-column
                prop="questCorrectRate"
                label="答题正确率">
                <template slot-scope="scope">
                  {{scope.row.questCorrectRate}}
                </template>
              </el-table-column>
              <el-table-column
                prop="newsCount"
                label="咨询浏览总数">
              </el-table-column>
            </el-table>
          </el-card>
    </el-card>
  </page-layout>
</template>
<script>
import PageLayout from "@/components/page-layout";
import { mapGetters } from "vuex";
import Status from "@/libs/status";
import Moment from "moment";
export default {
  beforeRouteEnter(to, from, next) {
    next(vm => {
      // vm.refresh();
    });
  },
  created() {},
  mounted() {},
  data() {
    return {
      loading: false,
      StateTypes: Status.StateTypes,
      SortType: Status.SortType,
      SortCategory: Status.SortCategory,
      value4: [],
      searchCondition: {}
    };
  },
  computed: {
    ...mapGetters({
      areaStatisList: "areaStatisList"
    })
  },
  methods: {
    getPageChange(val) {
      this.searchCondition.startDate = "";
      this.searchCondition.endDate = "";
      this.loading = true;
      if (this.value4 && this.value4.length > 0) {
        this.searchCondition.startDate = Moment(this.value4[0]).format(
          "YYYY-MM-DD"
        );
        this.searchCondition.endDate = Moment(this.value4[1]).format(
          "YYYY-MM-DD"
        );
      }
      var tem = Object.assign({ pageIndex: val - 1 }, this.searchCondition);
      this.$store.dispatch("complexAreaResultS", tem).then(ret => {
        this.loading = false;
      });
    },
    refresh() {
      this.getPageChange(1);
    },
    back() {
      this.showEditor = false;
      this.refresh();
    }
  },
  components: {
    PageLayout
  }
};
</script>
<style scoped>
</style>
